function TempoResourceImportController(importCallback){
	
	var $uploadForm = $("#tempo-resource-import-upload-form");
	var $uploadButton = $("#tempo-resource-import-upload-button");
	var $importDsDialog = $("#tempo-resource-import-ds-match-dialog");
	var $importTableDialog = $("#tempo-resource-import-table-match-dialog");
	var $checkbox = $('#tempo-resource-import-ds-match-checkbox');
	
	var $importFrom = 'resource';
	
	
	
	/**
	 * 初始化方法
	 */
	this.init = function(){
		Eventbus.one("importExportHandler.temporesource",importExportHandler,this);
		initImportButton();
	}
	
	/**
	 * 初始化导入按钮
	 */
	var initImportButton = function(){
		var uploadFileBtn = $("#tempo-resource-import-upload-button");
		uploadFileBtn.unbind("change").bind("change",function(){
			importFileSubmit();
		});
	}
	
	/**
	 * 清除值
	 */
	var clearInputValue = function(){
		$(".tempo-achievewatch-list-item-impexp-selected").focus();
		$("#tempo-resource-import-upload-form")[0].reset() 
	}
	
	
	/**
	 * 导入导出入口
	 */
	var importExportHandler = function(itemData, type, isPub,workSpaceId){
		if(type == 'import'){
			importHandler(itemData, isPub,workSpaceId);
		}else{
			exportHandler(itemData);
		}
	}
	
	/**
	 * 导入操作
	 */
	var importHandler = function(data, isPub,workSpaceId){
		if (isPub) {
			$uploadForm.find('input[name="projectId"]').val(data.id);
			$uploadForm.find('input[name="workSpaceId"]').val(data.workSpaceId);
		} else {
			var folderId=data.id;
			if(folderId==""||folderId==undefined){
				folderId="-1"
			}
			$uploadForm.find('input[name="folderId"]').val(folderId);
			$uploadForm.find('input[name="workSpaceId"]').val(workSpaceId);
			$uploadForm.find('input[name="workSpaceType"]').val(data.workSpaceType);
		}
		$uploadButton[0].click();
	}
	
	
	/**
	 * 导出操作
	 */
	var exportHandler = function(data){
		var id = data.ID || data.id;
		$.ajax({
			url:contextPath + '/themeDealController/canExport',
			data:{
				id: id
			},
			type:'post',
			success:function(data){
				if(data.flag){
					var url = contextPath + '/themeDealController/exportTheme?id=' + id;
					window.open(url);
				}else{
					$("<div/>").alert({
						msg:data.errorMsg,
						ok:function(){
							clearInputValue();
						}
					});
				}
			}
		})
	}
	
	
	/**
	 * 选择文件进行上传
	 */
	var importFileSubmit = function(){
		var fileSize = $("#tempo-resource-import-upload-button")[0].files[0].size;
		if(fileSize <= 0){
			$("<div/>").alert({
				msg:TempoUtils.locale("resource.empty_file_not_export"),
				ok:function(){
					clearInputValue();
				}
			});
			return;
		}
		var progress = $("<div/>").tempoprogressbar();
		$uploadForm.ajaxSubmit({
			dataType:'json',
			beforeSubmit:function(result){
				return true; 
			},
			success:function(resultData){
				progress.tempoprogressbar("destroy");
				if(resultData.isNeedChoose){
					//发现相同主题ID，用户选择覆盖或者新增
					chooseImportMethod(resultData);
					return;
				}
				
				if(resultData.isNeedMatch){
					//主题中包含数据模型，此时需要进行数据源与模型匹配
					initDataSourceMatchDialog(resultData, $uploadForm.find('input[name="folderId"]').val());
					return;
				}
				
				if(resultData.flag){
					var resourceData = resultData.currentTempoResource;
					if(importCallback){
						importCallback(resultData.currentTempoResource);
					}
					$("#tempo-resource-import-upload-form")[0].reset(); 
				}else{
					$("<div/>").alert({
						msg:resultData.errorMsg,
						ok:function(){
							clearInputValue()
						}
					});
				}
			},
			error:function(e){
				progress.tempoprogressbar("destroy");
				TempoUtils.uploadErrorHandler(e);
			}
		});
	}
	
	
	/**
	 * 选择当如方式
	 */
	var chooseImportMethod = function(result) {
		var msg = "<p style='font-size:14px'>已发现相同应用["
				+ result.targetResourceName + "]，请选择导入模式</p>";
		delete result['targetResourceName'];
		delete result['isNeedChoose'];
		var dialog = $("<div/>").appendTo($('body'));
		dialog.html(msg);
		dialog.dialog({
			width : 350,
			height : 200,
			title : '',
			modal : true,
			resizable : false,
			buttons : [{
				text : '覆盖',
				id:"tempo-import-choose-cover-button",
				click : function() {
					result.parseResult['mode'] = 'cover';
					toSaveImport(result,dialog,"tempo-import-choose-cover-button");
				}
			},{
				text : '新增',
				id:"tempo-import-choose-add-button",
				click : function() {
					toSaveImport(result,dialog,"tempo-import-choose-add-button");
				}
			}]
		});
	}
	
	
	/**
	 * 导入
	 */
	var toSaveImport = function(result,dialog,button){
		$('#' + button).button("disable");
		var progress = $("<div/>").tempoprogressbar();
		$.ajax({
			url:contextPath + '/themeDealController/importTheme',
			data:{
				parseResult: JSON.stringify(result.parseResult)
			},
			type:'post',
			success:function(resultData){
				progress.tempoprogressbar("destroy");
				if (resultData.isNeedMatch) {
					// 主题中包含数据模型，此时需要进行数据源与模型匹配
					initDataSourceMatchDialog(resultData, $uploadForm.find(
							'input[name="folderId"]').val());
					dialog.dialog('close');
					return;
				}
				if (resultData.flag) {
					var resourceData = resultData.currentTempoResource;
					if (importCallback) {
						importCallback(resultData.currentTempoResource);
					}
					$("#tempo-resource-import-upload-form")[0].reset();
					dialog.dialog('close');
				} else {
					$("<div/>").alert({
						msg : resultData.errorMsg,
						ok : function() {
							clearInputValue()
						}
					});
					$('#' + button).button("enable");
				}
			}
		});
	}
	
	//***************************数据源匹配相关开始**********************************
	/**
	 * 初始化数据源匹配弹出框
	 */
	var initDataSourceMatchDialog = function(resultData, folderId){
		$importDsDialog.dialog({
			title:TempoUtils.locale("bidesign.import_theme"),
			width:800,
			height:550,
			modal:true,
			resizable:false,
			close:function(){
				$importDsDialog.dialog("destroy");
				$importDsDialog.find("tbody").remove();
				clearInputValue();
				$.ajax({
					url:contextPath + "/themeDealController/deleteTempFile",
					type:'post',
					success:function(){}
				})
			},
			open:function(){
				$checkbox.checkbox({});
				initDataSourceMatchPage(resultData);
			},
			buttons:[{
				text:TempoUtils.locale("resource.next_step"),
				click:function(){
					//获取数据源的匹配结果
					var dataSourceMatchResult = getDataSourceMatchResult();
					//如果没有保留任何数据源，则直接执行导入即可
					if(!dataSourceMatchResult || $.isEmptyObject(dataSourceMatchResult)){
						saveToImport({},{},resultData,null);
						return;
					}
					
					//是否忽略未使用到的数据表
					//如果忽略
					var enableIgnorTable = $checkbox[0].checked;
					if(enableIgnorTable){
						ignorTables(dataSourceMatchResult,resultData,enableIgnorTable);
						return;
					}
					//初始化数据表匹配页面
					initTableMatchDialog(dataSourceMatchResult,resultData,null,enableIgnorTable);
				}
			},{
				type: 'cancel',
				click:function(){
					$importDsDialog.dialog("close"); 
				}
			}]
		});
	}
	
	
	/**
	 * 检测需要忽略的表
	 */
	var ignorTables = function(dataSourceMatchResult,resultData,enableIgnorTable){
		var folderId = resultData.parseResult.folderId;
		var projectId = resultData.parseResult.projectId;
		var projectAuthor = resultData.parseResult.projectAuthor;
		var projectOrgId = resultData.parseResult.projectOrgId;
		var progress = $("<div/>").tempoprogressbar();
		$.ajax({
			url:contextPath + '/themeDealController/ignorTables',
			data:{
				dataSourceMapping:JSON.stringify(dataSourceMatchResult),
				projectId:projectId,
				from:'resource',
				projectOrgId:projectOrgId,
				projectAuthor:projectAuthor,
				folderId : folderId
			},
			type:'post',
			success:function(data){
				progress.tempoprogressbar("destroy");
				if(data.import == true){
					$importDsDialog.dialog("close"); 
					try{
						$importTableDialog.dialog("close");
					}catch(e){
					}
					
					if($importFrom == 'resource'){
						var resourceData = data.currentTempoResource;
						if(importCallback){
							importCallback(resourceData);
						}
					}else{
						$(".tempo-achievewatch-list-item-impexp-selected").next(".tempo-achievewatch-list-project-children").remove();
						$(".tempo-achievewatch-list-item-impexp-selected").trigger("click");
					}
					$("#tempo-resource-import-upload-form")[0].reset() 
				}else{
					//初始化数据表匹配页面
					initTableMatchDialog(dataSourceMatchResult,resultData,data.usedTables,enableIgnorTable);
				}
			}
		});
	}
	
	/**
	 * 获取数据源匹配结果。
	 */
	var getDataSourceMatchResult = function(){
		var tableTr = $importDsDialog.find('.tempo-resource-datasource-mapping-tr');
		var dsMapping = {};
		if(tableTr && tableTr.length > 0){
			for(var i=0;i<tableTr.length;i++){
				var trItem = $(tableTr[i]);
				var sourceCode = trItem.attr('sourcecode');
				var targetCode = trItem.find("select").val();
				dsMapping[sourceCode] = targetCode;
			}
		}
		return dsMapping;
	}
	
	
	/**
	 * 初始化页面
	 */
	var initDataSourceMatchPage = function(resultData){
		//表格
		var tablePanel = $importDsDialog.find('#tempo-resource-import-ds-match-table');
		//webapi数据源
		var webapiDatasource = resultData.webapiDataSource;
		//目标数据源
		var targetDataSources = resultData.targetDataSources;
		//导入数据源
		var sourceDataSources = resultData.parseResult.dataSources;
		var mappingTargetDataSources = transTargetDataSources(targetDataSources);
		var selectNotHasPrestoHtml = renderSelectHtmlNotHasPresto(targetDataSources);
		var renderSelectIsPrestoHtml = renderSelectHtmlIsPresto(targetDataSources);
		var renderSelectWebapiHtml = renderSelectHtmlWebapi(webapiDatasource);
		//一个数据源一行
		for(var dataSourceName in sourceDataSources){
			var dataSourceItem = sourceDataSources[dataSourceName];
			var dataSourceType = dataSourceItem.type;
			var dataSourceCode = dataSourceItem.code;
			var tr = $("<tr/>",{
				sourcecode:dataSourceCode
			}).addClass("tempo-resource-datasource-mapping-tr").appendTo(tablePanel);
			var sourceTd = $("<td/>").css({"text-align":"center","width":"200px"}).text(dataSourceName + '(' + dataSourceType + ')');
			var targetId = null;
			if(dataSourceType == "presto"){
				targetId = $("<td/>").css({"text-align":"center","width":"260px"}).html(renderSelectIsPrestoHtml);
			}else if(dataSourceType == 'webmem'){
				targetId = $("<td/>").css({"text-align":"center","width":"260px"}).html(renderSelectWebapiHtml);
			}else{
				targetId = $("<td/>").css({"text-align":"center","width":"260px"}).html(selectNotHasPrestoHtml);
			}
			sourceTd.appendTo(tr);
			targetId.appendTo(tr);
			
			//匹配到的数据源
			var matchds = mappingTargetDataSources[dataSourceName];
			if(matchds){
				//如果匹配到，则选择改数据源
				targetId.find('option[value="'+matchds.code+'"]').attr("selected",true);
			}else{
				//如果未匹配到，则选中第一个。
				$(targetId.find('option')[0]).attr("selected",true);
			}
		}
		tablePanel.find("select").selectmenu({width:'150px'});
	}
	
	var renderSelectHtmlWebapi = function(webapiDatasource){
		if(webapiDatasource){
			var html = '<select>';
			html += '<option iswebapi="true" value="'+webapiDatasource.code+'">' + webapiDatasource.name + '</option>';
			html += '</select>';
			return html;
		}
		return "";
	}
	
	
	var renderSelectHtmlNotHasPresto = function(targetDataSources){
		var html = '<select>';
		if(targetDataSources && targetDataSources.length > 0){
			for(var i=0;i<targetDataSources.length;i++){
				var item = targetDataSources[i];
				if(item.type == 'presto'){
					continue;
				}
				var name = item.name;
				var code = item.code;
				html += '<option value="'+code+'">' + name + '</option>';
			}
		}
		html += '</select>';
		return html;
	}
	
	var renderSelectHtmlIsPresto = function(targetDataSources){
		var html = '<select>';
		if(targetDataSources && targetDataSources.length > 0){
			for(var i=0;i<targetDataSources.length;i++){
				var item = targetDataSources[i];
				if(item.type == 'presto'){
					var name = item.name;
					var code = item.code;
					html += '<option value="'+code+'">' + name + '</option>';
				}
			}
		}
		html += '</select>';
		return html;
	}
	
	
	/**
	 * 转换目标数据源
	 */
	var transTargetDataSources = function(targetDataSources){
		var mapping = {};
		if(targetDataSources && targetDataSources.length > 0){
			for(var i=0;i<targetDataSources.length;i++){
				var item = targetDataSources[i];
				mapping[item.name] = item;
			}
		}
		return mapping;
	}
	
	//***************************数据源匹配相关结束**********************************
	
	
	//***************************数据表匹配相关开始**********************************
	/**
	 * 初始化数据源匹配弹出框
	 */
	var initTableMatchDialog = function(dataSourceMapping,resultData,usedTables,enableIgnorTable){
		$importTableDialog.dialog({
			title:TempoUtils.locale("bidesign.import_theme"),
			width:800,
			height:550,
			modal:true,
			resizable:false,
			closable:false,
			dialogClass:'tempo-import-dialog-no-close',
			close:function(){
				$importTableDialog.dialog("destroy").remove();
				clearInputValue();
			},
			open:function(){
				initTableMatchPage(dataSourceMapping,resultData,usedTables,enableIgnorTable);
			},
			buttons:[{
				text:TempoUtils.locale("resource.back_step"),
				click:function(){
					//不关闭数据源匹配框
					$importTableDialog.dialog("close");
				}
			},{
				text:TempoUtils.locale("resource.import_test"),
				click:function(){
					//获取表的匹配结果
					var tableMatchResult = getTablesMatchResult();
					if(tableMatchResult.flag === false){
						$("<div/>").alert({
							msg:tableMatchResult.msg
						});
						return;
					}
					sendToTest(dataSourceMapping,tableMatchResult,usedTables,enableIgnorTable);
				}
			},{
				text:TempoUtils.locale("resource.import"),
				id:'tempo-resource-impexp-import-button',
				disabled:true,
				click:function(){
					//获取表的匹配结果
					var tableMatchResult = getTablesMatchResult();
					if(tableMatchResult.flag === false){
						$("<div/>").alert({
							msg:tableMatchResult.msg
						});
						return;
					}
					saveToImport(dataSourceMapping,tableMatchResult,resultData,usedTables);
				}
			},{
				type : 'cancel',
				click:function(){
					$importDsDialog.dialog("close"); 
					$importTableDialog.dialog("close");
				}
			}]
		});
	}
	
	
	/**
	 * 导入
	 */
	var saveToImport = function(dataSourceMapping,tableSchemaMapping,resultData,usedTables){
		var folderId = resultData.parseResult.folderId;
		var projectId = resultData.parseResult.projectId;
		var projectAuthor = resultData.parseResult.projectAuthor;
		var projectOrgId = resultData.parseResult.projectOrgId;
		var mode = resultData.parseResult.mode;
		var originResourceName = resultData.parseResult.originResourceName;
		var progress = $("<div/>").tempoprogressbar();
		$.ajax({
			url:contextPath + '/themeDealController/saveImport',
			data:{
				dataSourceMapping:JSON.stringify(dataSourceMapping),
				tableSchemaMapping:JSON.stringify(tableSchemaMapping),
				usedTables:JSON.stringify(usedTables),
				projectId:projectId,
				from:'resource',
				projectOrgId:projectOrgId,
				projectAuthor:projectAuthor,
				folderId : folderId,
				mode:mode,
				originResourceName:originResourceName,
				workSpaceId:$('.theme-container').attr('workspaceid')
			},
			type:'post',
			success:function(data){
				progress.tempoprogressbar("destroy");
				if(data.flag){
					$importDsDialog.dialog("close"); 
					try{
						$importTableDialog.dialog("close");
					}catch(e){
					}
					
					if($importFrom == 'resource'){
						var resourceData = data.currentTempoResource;
						if(importCallback){
							importCallback(resourceData,mode);
						}
					}else{
						$(".tempo-achievewatch-list-item-impexp-selected").next(".tempo-achievewatch-list-project-children").remove();
						$(".tempo-achievewatch-list-item-impexp-selected").trigger("click");
					}
					$("#tempo-resource-import-upload-form")[0].reset() 
				}else{
					$("<div/>").alert({
						msg:data.errorMsg
					});
				}
			}
		});
	}
	
	/**
	 * 测试
	 */
	var sendToTest = function(dataSourceMapping,tableSchemaMapping,usedTables,enableIgnorTable){
		var progress = $("<div/>").tempoprogressbar();
		$.ajax({
			url:contextPath + '/themeDealController/test',
			data:{
				dataSourceMapping:JSON.stringify(dataSourceMapping),
				tableSchemaMapping:JSON.stringify(tableSchemaMapping),
				usedTables:JSON.stringify(usedTables),
				enableIgnorTable:enableIgnorTable,
				from:'resource'
			},
			type:'post',
			success:function(data){
				progress.tempoprogressbar("destroy");
				var testResult = data.mappingResult;
				if(testResult){
					//如果表全部测试成功之后，才能进行导入，
					//SQL测试失败时，可以导入，导入进去手工调整SQL
					var isTableTestSuccess = true;
					for(var dataSourceCode in testResult){
						var tablesInfo = testResult[dataSourceCode];
						if(tablesInfo){
							for(var tableId in tablesInfo){
								var $tabItem = $importTableDialog.find('#' + dataSourceCode);
								
//								var $errorSpan = $tabItem.find('#' + tableId);
								var $errorSpan = $tabItem.find('span[id="'+tableId+'"]');
								$errorSpan.children().remove();
								
								if(tablesInfo[tableId] == "1"){
									$("<span/>",{
										"class":"ui-icon tempo-ui-icon tempo-ui-icon-no-mutual tempo-ui-icon-red-circle-check-thin",
										"title":TempoUtils.locale("resource.success")
									}).appendTo($errorSpan);
								}else{
									$("<span/>",{
										"class":"ui-icon tempo-ui-icon tempo-ui-icon-no-mutual tempo-ui-icon-red-circle-errorprompt",
										"title":tablesInfo[tableId]
									}).appendTo($errorSpan);
								}
								var selectedTable =  $errorSpan.parents("tr").find('input').data("selectedTable");
								var tableType = $errorSpan.parents("tr").attr("datatabletype");
								
								//如果是sql类型的，并且没有匹配的表，则即使执行报错，也可以导入，导入后在对SQL进行调整。
								if(!(tableType == "sql" && !selectedTable)){
									if(tablesInfo[tableId] != "1"){
										isTableTestSuccess = false;
									}
								}
							}
						}
					}
					if(isTableTestSuccess){
						$("#tempo-resource-impexp-import-button").button('enable');
					}
				}
			}
		});
	}
	
	
	/**
	 * 获取数据表的匹配结果
	 */
	var getTablesMatchResult = function(){
		var $tabItems = $importTableDialog.find("div.tempo-resource-import-tab-item-div");
		var mapping = {};
		for(var i=0;i<$tabItems.length;i++){
			var tabItem = $tabItems[i];
			var dataSourceCode = $(tabItem).attr("id");
			var tabName = $(tabItem).attr("sourcename");
			var dataTableMapping = {};
			if($(tabItem).find("table.tempo-resource-import-table-load-over").length > 0){
				var trs = $(tabItem).find("tr[datatable-id]");
				for(var j=0;j<trs.length;j++){
					var dataTableId = $(trs[j]).attr("datatable-id");
					var selectedTable = $(trs[j]).find('input').data("selectedTable");
					dataTableMapping[dataTableId] = selectedTable;
				}
			}else{
				continue
			}
			mapping[dataSourceCode]  = dataTableMapping;
		}
		return mapping;
	}

	
	/**
	 * 初始化表匹配页面
	 */
	var initTableMatchPage = function(dataSourceMapping,resultData,usedTables,enableIgnorTable){
		$importTableDialog.empty();
		var $tab = $("<div/>",{
			'id':'tempo-resource-import-table-match-tab'
		}).css({
			width:'100%',
			height:'100%'
		}).appendTo($importTableDialog);
		var sourceDataSources = resultData.parseResult.dataSources;
		var ul = $("<ul/>").appendTo($tab);
		if(sourceDataSources){
			var dataSourceItem,dataSourceCode,li,lia,div,targetdiv;
			for(var dataSourceName in sourceDataSources){
				var sourceDataSourceCode = sourceDataSources[dataSourceName].code
				if(!dataSourceMapping[sourceDataSourceCode]){
					continue;
				}
				
				if(enableIgnorTable == true && usedTables 
						&& (!usedTables[sourceDataSourceCode] 
						|| usedTables[sourceDataSourceCode].length<=0)){
					continue;
				}
				dataSourceItem = sourceDataSources[dataSourceName];
				dataSourceCode = dataSourceItem.code;
				li = $("<li/>",{
					"li-id":dataSourceCode
				}).appendTo(ul);
				lia = $("<a/>",{
					'href':'#' + dataSourceCode
				}).appendTo(li);
				$("<span/>").text(dataSourceName).appendTo(lia);
				
				div = $("<div/>",{
					"id":dataSourceCode,
					"class":"tempo-resource-import-tab-item-div",
					"sourcename":dataSourceName
				}).appendTo($tab);
				
				targetdiv =  $("<div/>").appendTo(div);
				targetdiv.css({
					height:'350px',
					overflow:"auto"
				})
				$("<table class='formLayout'><thead><tr><th>" + TempoUtils.locale("resource.import_table_name") + "</th><th>" + TempoUtils.locale("resource.import_schema_name") + "</th><th>" + TempoUtils.locale("resource.import_target_table") + "</th></tr></thead></table>").appendTo(targetdiv);
			}
			var firstTabDataSourceCode = $(ul.find('li')[0]).attr("li-id");
			//匹配到的数据源CODE
			var targetDataSourceCode = dataSourceMapping[firstTabDataSourceCode];
			//渲染Tab项的内容。
			renderTabItemContent(firstTabDataSourceCode,resultData,targetDataSourceCode,usedTables,enableIgnorTable);
			//渲染Tab页
			$tab.tabs({
				activate:function(ui,e){
					var newPanel = e.newPanel;
					var table = newPanel.find("table");
					if(!table.hasClass("tempo-resource-import-table-load-over")){
						var newPanelDatasourceCode = newPanel.attr("id");
						var paramDataSourceCode = dataSourceMapping[newPanelDatasourceCode];
						renderTabItemContent(newPanelDatasourceCode,resultData,paramDataSourceCode,usedTables,enableIgnorTable);
					}
				}
			});
			var targetLis = $tab.find('li[li-id]');
			if(targetLis && targetLis.length > 0){
				for (var i = 0; i < targetLis.length; i++) {
					if(i > 0){
						$(targetLis[i]).find('a').trigger('click');
					}
				}
				$(targetLis[0]).find('a').trigger('click');
			}
		}
	}
	
//	/**
//	 * 选中加载schema
//	 */
//	var loadSchemaForPage = function(paramDataSourceCode,targetTabItemId,resultData){
//		var progress = $("<div/>").tempoprogressbar();
//		//加载模式数据库的模式名
//		$.ajax({
//			url:contextPath + '/themeDealController/getShemas',
//			data:{
//				dataSourceCode:paramDataSourceCode
//			},
//			type:'post',
//			success:function(schemaInfo){
//				progress.tempoprogressbar("destroy");
//				if(schemaInfo.flag){
//					var schemas = schemaInfo.schemas;
//					//渲染Tab项的内容。
//					renderTabItemContent(targetTabItemId,schemas,resultData);
//					//渲染Tab页
//				}
//			}
//		});
//	}
	
	
	var currentDataSourceInfo = function(dataSources ,code){
		for (var i = 0; i < dataSources.length; i++) {
			if(dataSources[i].code == code){
				return dataSources[i];
			}
		}
		return null;
	}
	/**
	 * 渲染Tab项的内容
	 */
	var renderTabItemContent = function(sourceDataSourceCode,resultData,targetDataSourceCode,usedTables,enableIgnorTable){
		var sourceDataSources = resultData.parseResult.dataSources;
		var _targetDataSource = resultData.targetDataSources||[];
		var _currentDataSourceInfo = currentDataSourceInfo(_targetDataSource,targetDataSourceCode);
		if(!_currentDataSourceInfo){
			return null;
		}
		var targetDiv = $("#" + sourceDataSourceCode);
		var sourceDataSourceName = targetDiv.attr("sourcename");
		var target = targetDiv.find("table");
		target.addClass("tempo-resource-import-table-load-over");
		var tables = sourceDataSources[sourceDataSourceName].tables;
		if(tables && tables.length){
			//获取所有被关联数据集引用的表
			var tablesRefByChartSet = getChartSetTables(tables);
			for(var i=0;i<tables.length;i++){
				//tables[i].id 为模型表数据库的ID
				var content = tables[i].content;
				var dataTable = $.parseJSON(content);
				//关联数据集不匹配
				if(dataTable.type == 'chart' 
					|| dataTable.type == 'collect' 
						|| dataTable.type == 'COLUMN2ROW' 
							|| dataTable.type == 'UNION'){
					continue;
				}
				if(enableIgnorTable == true && usedTables){
					var usedTableIds = usedTables[sourceDataSourceCode] || [];
					if($.inArray(dataTable.name,usedTableIds) < 0){
						continue;
					}
				}
				
				var dataTableSchema = dataTable.schema;
				var dataTableType = dataTable.type;
				
				//数据行
				var tr = $("<tr/>",{
					datatabletype:dataTableType,
					//是否被关联数据集引用着，如果引用着，选择表时，不能选规则数据集以及SQL数据集
					isRefByChart:((tablesRefByChartSet.indexOf(dataTable.name) >= 0) || (dataTableType == 'sql'))
				}).appendTo(target);
				tr.attr("datatable-id",tables[i].name);
				//当前表名称
				var sourceNameTd = $("<td/>").css({"text-align":"center","width":"250px"}).appendTo(tr);
				var sourceNameSpan = $("<span/>").appendTo(sourceNameTd);
				sourceNameSpan.css({
					"display": "block",
				    "width": "250px",
				    "overflow": "hidden",
				    "white-space": "nowrap",
				    "text-overflow": "ellipsis"
				});
				//当前(catalog,模式名)
				var sourceSchemaTd = $("<td/>").css({"text-align":"center","width":"80px"}).appendTo(tr);
				//目标(catalog,模式名)
				var targetSchemaTd = $("<td/>").css({"text-align":"left"}).appendTo(tr);
//				var targetSchemaTd = $("<td/>").css({"text-align":"left","position":"absolute"}).appendTo(tr);
				//测试后的提示信息
				var errorMsgTd = $("<td/>").css("text-align","right").appendTo(tr);
				$("<span/>",{
					"id":tables[i].name
				}).appendTo(errorMsgTd);
				
				if(dataTableType == "sql" || dataTableType == "msql"){
					//如果是SQL数据集，特殊处理
					sourceNameSpan.text(dataTable.title);
					sourceNameSpan.attr("title",dataTable.title);
					sourceSchemaTd.text("——");
				}else if(dataTableType == 'table' && dataTable.dataPrivilegeRuleId){
					//其他
					sourceNameSpan.text(dataTable.title);
					sourceNameSpan.attr("title",dataTable.title);
					sourceSchemaTd.text("——");
				}else{
					sourceNameSpan.text(dataTable.originName);
					sourceNameSpan.attr("title",dataTable.originName)
					if(_currentDataSourceInfo.type == 'datafusion'){
						sourceSchemaTd.text("——");
					}else{
						sourceSchemaTd.text(dataTable.schema);
					}
				}
				var inputContainer = $('<div/>').appendTo(targetSchemaTd);
				$("<input placeholder='" + TempoUtils.locale("resource.select_table_tip") + "'  class='tempo-import-mapping-select-table-button inputbox tempo-validatebox tempo-validator' readonly=readonly style='width:300px;cursor:pointer'/>").appendTo(targetSchemaTd);
				$("<span style='margin-left:-16px;margin-right:0px;cursor:pointer;' class='tempo-import-mapping-select-reset-button ui-icon tempo-ui-icon tempo-ui-icon-delete'  title='" + TempoUtils.locale("resource.clear") + "'/>").appendTo(targetSchemaTd);
			}
			
			//绑定事件
			target.find('input.tempo-import-mapping-select-table-button').off('click').on('click',function(){
				var $this = $(this);
				loadSelectTable(targetDataSourceCode,resultData,$this);
			});
			target.find('span.tempo-import-mapping-select-reset-button').off('click').on('click',function(){
				var $this = $(this);
				$this.parents("tr").find('input').data('selectedTable',null);
				$this.parents("tr").find('input').val("");
			});
		}
	}
	
	/**
	 * $.parseJSON(
	 */
	
	/**
	 * 找出所有被关联数据集引用的表
	 */
	var getChartSetTables = function(tables){
		var content,dataTable,result=[],config,children;
		for(var i=0;i<tables.length;i++){
			content = tables[i].content;
			dataTable = $.parseJSON(content);
			if(dataTable.type == 'chart' && dataTable.dataSqlSet && dataTable.dataSqlSet.config){
				config = $.parseJSON(dataTable.dataSqlSet.config);
				children = config.children;
				if(children && children.length > 0){
					for(var j=0;j<children.length;j++){
						result.push(children[j].table.name);
					}
				}
			}
		}
		return result;
	}
	
	
	
	/**
	 * 初始化选择表弹出框
	 */
	var loadSelectTable = function(dataSourceCode,resultData,target){
		var webapiDataSource = resultData.webapiDataSource;
		var url = contextPath+"/resource/import/selecttable";
		if(webapiDataSource && webapiDataSource.code == dataSourceCode){
			//webapi接口数据
			url = contextPath+"/resource/import/selectapitable";
		}
		$m.loadHtml(url,$("body"),"tempo-import-select-table-dialog",{
			dataSourceCode:dataSourceCode,
			//是否被关联数据集引用着，如果引用着，选择表时，不能选规则数据集以及SQL数据集
			isRefByChartSet:target.parents("tr").attr("isrefbychart"),
			allDataSources:resultData.targetDataSources,
			callback:function(targetDataSet){
				target.parents("tr").find('input').data('selectedTable',targetDataSet);
				target.parents("tr").find('input').val(targetDataSet.title);
				$("#tempo-resource-impexp-import-button").button("disable");
			}
		});
	}
}